package com.xiaozhichao.nosql.redis.pushsub;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPubSub;

public class SubThread implements Runnable {

    private final JedisPool jedisPool;
    private final String channel;
    private final JedisPubSub jedisPubSub;

    public SubThread(JedisPool jedisPool,String channel,JedisPubSub jedisPubSub) {
        this.jedisPool = jedisPool;
        this.channel = channel;
        this.jedisPubSub = jedisPubSub;
    }
    @Override
    public void run() {
        Jedis jedis = this.jedisPool.getResource();//连接池中取出一个连接
        jedis.subscribe(this.jedisPubSub,this.channel);
    }
}
